package com.example.leetdemo.plan1;

public class Sword016 {

    public int lengthOfLongestSubstring(String s) {
        int a = 0, sum = 0, l = 0;
        for (int i = 0; i < s.length(); i++) {
            int t = 1 << (s.charAt(i) - 'a');
            l++;
            if ((t & a) == 0) {
                sum = Math.max(sum, l);
                a += t;
            } else {
                a += t;
                for (int j = i - l + 1; j < i; j++) {
                    int t2 = 1 << (s.charAt(j) - 'a');
                    a -= t2;
                    l--;
                    if ((t2 & a) == 0) {
                        sum = Math.max(sum, l);
                        break;
                    }
                }
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        Sword016 sword016 = new Sword016();
        System.err.println(sword016.lengthOfLongestSubstring("abasacdefb"));
    }

}
